package com.ruoyi.web.controller.bargain;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.bargain.domain.BargainRegistration;
import com.ruoyi.bargain.service.IBargainRegistrationService;
import com.ruoyi.framework.web.base.BaseController;
import com.ruoyi.common.page.TableDataInfo;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.base.AjaxResult;

/**
 * 砍价报名 信息操作处理
 * 
 * @author lzy
 * @date 2019-03-07
 */
@Controller
@RequestMapping("/bargain/bargainRegistration")
public class BargainRegistrationController extends BaseController
{
    private String prefix = "bargain/bargainRegistration";
	
	@Autowired
	private IBargainRegistrationService bargainRegistrationService;
	
	@RequiresPermissions("bargain:bargainRegistration:view")
	@GetMapping()
	public String bargainRegistration()
	{
	    return prefix + "/bargainRegistration";
	}
	
	/**
	 * 查询砍价报名列表
	 */
	@RequiresPermissions("bargain:bargainRegistration:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(BargainRegistration bargainRegistration)
	{
		startPage();
        List<BargainRegistration> list = bargainRegistrationService.selectBargainRegistrationList(bargainRegistration);
		return getDataTable(list);
	}
	
	
	/**
	 * 导出砍价报名列表
	 */
	@RequiresPermissions("bargain:bargainRegistration:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(BargainRegistration bargainRegistration)
    {
    	List<BargainRegistration> list = bargainRegistrationService.selectBargainRegistrationList(bargainRegistration);
        ExcelUtil<BargainRegistration> util = new ExcelUtil<BargainRegistration>(BargainRegistration.class);
        return util.exportExcel(list, "bargainRegistration");
    }
	
	/**
	 * 新增砍价报名
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存砍价报名
	 */
	@RequiresPermissions("bargain:bargainRegistration:add")
	@Log(title = "砍价报名", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(BargainRegistration bargainRegistration)
	{		
		return toAjax(bargainRegistrationService.insertBargainRegistration(bargainRegistration));
	}

	/**
	 * 修改砍价报名
	 */
	@GetMapping("/edit/{id}")
	public String edit(@PathVariable("id") String id, ModelMap mmap)
	{
		BargainRegistration bargainRegistration = bargainRegistrationService.selectBargainRegistrationById(id);
		mmap.put("bargainRegistration", bargainRegistration);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存砍价报名
	 */
	@RequiresPermissions("bargain:bargainRegistration:edit")
	@Log(title = "砍价报名", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(BargainRegistration bargainRegistration)
	{		
		return toAjax(bargainRegistrationService.updateBargainRegistration(bargainRegistration));
	}
	
	/**
	 * 删除砍价报名
	 */
	@RequiresPermissions("bargain:bargainRegistration:remove")
	@Log(title = "砍价报名", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(bargainRegistrationService.deleteBargainRegistrationByIds(ids));
	}
	
}
